const gameContainer = document.getElementById('game-container');
const scoreElement = document.querySelector('.score');
let score = 0;

function createFruit() {
    const fruit = document.createElement('div');
    fruit.classList.add('fruit');
    const startX = Math.random() * (gameContainer.offsetWidth - 50);
    fruit.style.left = `${startX}px`;
    fruit.style.bottom = '0px';
    gameContainer.appendChild(fruit);

    const animationDuration = Math.random() * 3 + 2;
    fruit.animate([
        { bottom: '0px' },
        { bottom: `${gameContainer.offsetHeight}px` }
    ], {
        duration: animationDuration * 1000,
        easing: 'ease-in-out',
        fill: 'forwards'
    });

    fruit.addEventListener('click', () => {
        fruit.remove();
        score++;
        scoreElement.textContent = `得分: ${score}`;
    });

    setTimeout(() => {
        if (fruit.parentNode) {
            fruit.remove();
        }
    }, animationDuration * 1000);
}

setInterval(createFruit, 1000);